home *** CD-ROM | disk | FTP | other *** search
/ Datatid 1999 #12 / Datatid-1999-12.iso / internet / FP 2000 / fphover.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-04-06  |  9.1 KB  |  522 lines

  1. import java.applet.Applet;
  2. import java.applet.AudioClip;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Event;
  6. import java.awt.Font;
  7. import java.awt.FontMetrics;
  8. import java.awt.Graphics;
  9. import java.awt.Image;
  10. import java.awt.MediaTracker;
  11. import java.awt.image.FilteredImageSource;
  12. import java.awt.image.ImageObserver;
  13. import java.net.MalformedURLException;
  14. import java.net.URL;
  15.  
  16. public class fphover extends Applet {
  17.    private String m_image = "";
  18.    private String m_hoverImage = "";
  19.    private Color m_bgColor;
  20.    private Color m_color;
  21.    private Color m_hoverColor;
  22.    private String m_effectString;
  23.    private String m_sound;
  24.    private String m_hoverSound;
  25.    private String m_url;
  26.    private String m_target;
  27.    private String m_text;
  28.    private Color m_textColor;
  29.    private String m_textAlign;
  30.    private String m_textVAlign;
  31.    private String m_font;
  32.    private String m_fontStyle;
  33.    private int m_fontSize;
  34.    private final String PARAM_image;
  35.    private final String PARAM_hoverImage;
  36.    private final String PARAM_bgColor;
  37.    private final String PARAM_color;
  38.    private final String PARAM_hoverColor;
  39.    private final String PARAM_effect;
  40.    private final String PARAM_sound;
  41.    private final String PARAM_hoverSound;
  42.    private final String PARAM_url;
  43.    private final String PARAM_target;
  44.    private final String PARAM_text;
  45.    private final String PARAM_textColor;
  46.    private final String PARAM_textAlign;
  47.    private final String PARAM_textVAlign;
  48.    private final String PARAM_font;
  49.    private final String PARAM_fontStyle;
  50.    private final String PARAM_fontSize;
  51.    private int m_effect;
  52.    private Image m_srcImage;
  53.    private Image m_srcHoverImage;
  54.    private AudioClip m_audio;
  55.    private AudioClip m_hoverAudio;
  56.    private URL m_docUrl;
  57.    private int m_hover;
  58.    private int m_textWidth;
  59.    private boolean m_textMask;
  60.    private Image m_textImage;
  61.    private int m_iTextAlign;
  62.    private int m_iTextVAlign;
  63.    private int m_textImageWidth;
  64.    private int m_textImageHeight;
  65.    private boolean m_textImageError;
  66.    private boolean m_srcImageError;
  67.    private boolean m_srcHoverImageError;
  68.    private boolean m_applyEffectWait;
  69.    private FontMetrics m_fm;
  70.    private static final int COLOR = 0;
  71.    private static final int IMAGE = 1;
  72.    private static final int EFFECT = 2;
  73.    private int m_normalType;
  74.    private int m_hoverType;
  75.    private boolean m_noErase;
  76.    private int m_w;
  77.    private int m_h;
  78.    private int m_x;
  79.    private int m_y;
  80.  
  81.    public boolean mouseMove(Event var1, int var2, int var3) {
  82.       return true;
  83.    }
  84.  
  85.    public void stop() {
  86.    }
  87.  
  88.    public boolean mouseEnter(Event var1, int var2, int var3) {
  89.       this.m_hover = 1;
  90.       if (this.m_hoverAudio != null) {
  91.          this.m_hoverAudio.play();
  92.       }
  93.  
  94.       ((Applet)this).showStatus(this.m_url);
  95.       if (this.m_normalType != 1 || this.m_hoverType != 1 || !this.m_image.equals(this.m_hoverImage)) {
  96.          ((Component)this).repaint();
  97.       }
  98.  
  99.       return true;
  100.    }
  101.  
  102.    public boolean mouseExit(Event var1, int var2, int var3) {
  103.       this.m_hover = 0;
  104.       if (this.m_normalType != 1 || this.m_hoverType != 1 || !this.m_image.equals(this.m_hoverImage)) {
  105.          ((Component)this).repaint();
  106.       }
  107.  
  108.       return true;
  109.    }
  110.  
  111.    public void paint(Graphics var1) {
  112.       this.getXY();
  113.       if (this.m_hover == 0) {
  114.          if (!this.m_srcImageError) {
  115.             var1.drawImage(this.m_srcImage, 0, 0, this);
  116.          }
  117.       } else {
  118.          if (!this.m_srcHoverImageError) {
  119.             var1.drawImage(this.m_srcHoverImage, 0, 0, this);
  120.          }
  121.  
  122.          if (this.m_effect == 5) {
  123.             this.m_x += -1;
  124.             this.m_y += -1;
  125.          }
  126.  
  127.          if (this.m_effect == 6) {
  128.             ++this.m_x;
  129.             ++this.m_y;
  130.          }
  131.       }
  132.  
  133.       if (this.m_textMask) {
  134.          if (!this.m_textImageError) {
  135.             var1.drawImage(this.m_textImage, this.m_x, this.m_y, this);
  136.          }
  137.       } else {
  138.          var1.setColor(this.m_textColor);
  139.          var1.drawString(this.m_text, this.m_x, this.m_y);
  140.       }
  141.  
  142.    }
  143.  
  144.    public boolean mouseUp(Event var1, int var2, int var3) {
  145.       if (!this.m_url.equalsIgnoreCase("") && this.m_docUrl != null) {
  146.          if (this.m_target.equalsIgnoreCase("")) {
  147.             ((Applet)this).getAppletContext().showDocument(this.m_docUrl);
  148.          } else {
  149.             ((Applet)this).getAppletContext().showDocument(this.m_docUrl, this.m_target);
  150.          }
  151.       }
  152.  
  153.       if (this.m_audio != null) {
  154.          this.m_audio.play();
  155.       }
  156.  
  157.       return true;
  158.    }
  159.  
  160.    public String[][] getParameterInfo() {
  161.       String[][] var1 = new String[][]{{"image", "String", "Normal button image"}, {"hoverImage", "String", "Hover button image"}, {"bgColor", "int", "Background color"}, {"color", "int", "Normal color"}, {"hoverColor", "int", "Hover color"}, {"effect", "int", "Effect for hover image"}, {"sound", "String", "Sound Url"}, {"hoverSound", "String", "Hover sound Url"}, {"url", "String", "Url"}, {"target", "String", "Target frame"}, {"text", "String", "Text"}, {"textColor", "int", "Text color"}, {"textAlign", "String", "Text alignment"}, {"textVAlign", "String", "Text vertical alignment"}, {"font", "String", "Font"}, {"fontStyle", "String", "Font style"}, {"fontSize", "int", "Font size in points"}};
  162.       return var1;
  163.    }
  164.  
  165.    public void destroy() {
  166.    }
  167.  
  168.    public fphover() {
  169.       this.m_bgColor = Color.white;
  170.       this.m_color = Color.white;
  171.       this.m_hoverColor = Color.white;
  172.       this.m_effectString = "";
  173.       this.m_sound = "";
  174.       this.m_hoverSound = "";
  175.       this.m_url = "";
  176.       this.m_target = "";
  177.       this.m_text = "";
  178.       this.m_textColor = Color.black;
  179.       this.m_textAlign = "center";
  180.       this.m_textVAlign = "middle";
  181.       this.m_font = "Dialog";
  182.       this.m_fontStyle = "bold";
  183.       this.m_fontSize = 14;
  184.       this.PARAM_image = "image";
  185.       this.PARAM_hoverImage = "hoverImage";
  186.       this.PARAM_bgColor = "bgColor";
  187.       this.PARAM_color = "color";
  188.       this.PARAM_hoverColor = "hoverColor";
  189.       this.PARAM_effect = "effect";
  190.       this.PARAM_sound = "sound";
  191.       this.PARAM_hoverSound = "hoverSound";
  192.       this.PARAM_url = "url";
  193.       this.PARAM_target = "target";
  194.       this.PARAM_text = "text";
  195.       this.PARAM_textColor = "textColor";
  196.       this.PARAM_textAlign = "textAlign";
  197.       this.PARAM_textVAlign = "textVAlign";
  198.       this.PARAM_font = "font";
  199.       this.PARAM_fontStyle = "fontStyle";
  200.       this.PARAM_fontSize = "fontSize";
  201.       this.m_hoverType = 2;
  202.    }
  203.  
  204.    public void getXY() {
  205.       this.m_w = ((Component)this).size().width;
  206.       this.m_h = ((Component)this).size().height;
  207.       this.m_x = 0;
  208.       this.m_y = 0;
  209.       if (this.m_textMask) {
  210.          if (this.m_textImageWidth < 0 || this.m_textImageHeight < 0) {
  211.             return;
  212.          }
  213.  
  214.          if (this.m_iTextAlign == 0) {
  215.             this.m_x = (this.m_w - this.m_textImageWidth) / 2;
  216.          } else if (this.m_iTextAlign == 1) {
  217.             this.m_x = this.m_w - this.m_textImageWidth;
  218.          }
  219.  
  220.          if (this.m_iTextVAlign == 0) {
  221.             this.m_y = (this.m_h - this.m_textImageHeight) / 2;
  222.          } else if (this.m_iTextVAlign == 1) {
  223.             this.m_y = this.m_h - this.m_textImageHeight;
  224.          }
  225.       } else {
  226.          this.m_x = (this.m_w - this.m_textWidth) / 2;
  227.          this.m_y = (this.m_h + this.m_fm.getAscent() - this.m_fm.getDescent()) / 2;
  228.       }
  229.  
  230.    }
  231.  
  232.    public void update(Graphics var1) {
  233.       if (!this.m_noErase) {
  234.          var1.clearRect(0, 0, ((Component)this).size().width, ((Component)this).size().height);
  235.       }
  236.  
  237.       this.paint(var1);
  238.    }
  239.  
  240.    public void start() {
  241.    }
  242.  
  243.    public String getAppletInfo() {
  244.       return "Name: fphover\r\n" + "Author: Tom Blumer\r\n" + "Created with Microsoft Visual J++ Version 1.1";
  245.    }
  246.  
  247.    public boolean mouseDown(Event var1, int var2, int var3) {
  248.       return true;
  249.    }
  250.  
  251.    public void init() {
  252.       String var1 = ((Applet)this).getParameter("image");
  253.       if (var1 != null) {
  254.          this.m_image = var1;
  255.       }
  256.  
  257.       if (!this.m_image.equalsIgnoreCase("")) {
  258.          this.m_normalType = 1;
  259.       }
  260.  
  261.       var1 = ((Applet)this).getParameter("hoverImage");
  262.       if (var1 != null) {
  263.          this.m_hoverImage = var1;
  264.       }
  265.  
  266.       if (!this.m_hoverImage.equalsIgnoreCase("")) {
  267.          this.m_hoverType = 1;
  268.       }
  269.  
  270.       var1 = ((Applet)this).getParameter("bgColor");
  271.       if (var1 != null) {
  272.          if (var1.charAt(0) == '#') {
  273.             var1 = var1.substring(1);
  274.          }
  275.  
  276.          this.m_bgColor = new Color(Integer.parseInt(var1, 16));
  277.       }
  278.  
  279.       var1 = ((Applet)this).getParameter("color");
  280.       if (var1 != null) {
  281.          if (var1.charAt(0) == '#') {
  282.             var1 = var1.substring(1);
  283.          }
  284.  
  285.          this.m_color = new Color(Integer.parseInt(var1, 16));
  286.       }
  287.  
  288.       var1 = ((Applet)this).getParameter("hoverColor");
  289.       if (var1 != null) {
  290.          if (var1.charAt(0) == '#') {
  291.             var1 = var1.substring(1);
  292.          }
  293.  
  294.          this.m_hoverColor = new Color(Integer.parseInt(var1, 16));
  295.       }
  296.  
  297.       var1 = ((Applet)this).getParameter("effect");
  298.       if (var1 != null) {
  299.          this.m_effectString = var1;
  300.       }
  301.  
  302.       this.m_effect = 2;
  303.       if (this.m_effectString.equalsIgnoreCase("fill")) {
  304.          this.m_effect = 0;
  305.       } else if (this.m_effectString.equalsIgnoreCase("average")) {
  306.          this.m_effect = 1;
  307.       } else if (this.m_effectString.equalsIgnoreCase("glow")) {
  308.          this.m_effect = 2;
  309.       } else if (this.m_effectString.equalsIgnoreCase("reverseGlow")) {
  310.          this.m_effect = 3;
  311.       } else if (this.m_effectString.equalsIgnoreCase("lightglow")) {
  312.          this.m_effect = 4;
  313.       } else if (this.m_effectString.equalsIgnoreCase("bevelOut")) {
  314.          this.m_effect = 5;
  315.       } else if (this.m_effectString.equalsIgnoreCase("bevelIn")) {
  316.          this.m_effect = 6;
  317.       }
  318.  
  319.       var1 = ((Applet)this).getParameter("sound");
  320.       if (var1 != null) {
  321.          this.m_sound = var1;
  322.       }
  323.  
  324.       var1 = ((Applet)this).getParameter("hoverSound");
  325.       if (var1 != null) {
  326.          this.m_hoverSound = var1;
  327.       }
  328.  
  329.       var1 = ((Applet)this).getParameter("url");
  330.       if (var1 != null) {
  331.          this.m_url = var1;
  332.       }
  333.  
  334.       var1 = ((Applet)this).getParameter("target");
  335.       if (var1 != null) {
  336.          this.m_target = var1;
  337.       }
  338.  
  339.       var1 = ((Applet)this).getParameter("text");
  340.       if (var1 != null) {
  341.          this.m_text = var1;
  342.       }
  343.  
  344.       var1 = ((Applet)this).getParameter("textColor");
  345.       if (var1 != null) {
  346.          if (var1.charAt(0) == '#') {
  347.             var1 = var1.substring(1);
  348.          }
  349.  
  350.          this.m_textColor = new Color(Integer.parseInt(var1, 16));
  351.       }
  352.  
  353.       var1 = ((Applet)this).getParameter("textAlign");
  354.       if (var1 != null) {
  355.          this.m_textAlign = var1;
  356.       }
  357.  
  358.       this.m_iTextAlign = 0;
  359.       if (this.m_textAlign.equalsIgnoreCase("left")) {
  360.          this.m_iTextAlign = -1;
  361.       } else if (this.m_textAlign.equalsIgnoreCase("right")) {
  362.          this.m_iTextAlign = 1;
  363.       }
  364.  
  365.       var1 = ((Applet)this).getParameter("textVAlign");
  366.       if (var1 != null) {
  367.          this.m_textVAlign = var1;
  368.       }
  369.  
  370.       this.m_iTextVAlign = 0;
  371.       if (this.m_textVAlign.equalsIgnoreCase("top")) {
  372.          this.m_iTextVAlign = -1;
  373.       } else if (this.m_textVAlign.equalsIgnoreCase("bottom")) {
  374.          this.m_iTextVAlign = 1;
  375.       }
  376.  
  377.       var1 = ((Applet)this).getParameter("font");
  378.       if (var1 != null) {
  379.          this.m_font = var1;
  380.       }
  381.  
  382.       this.m_textMask = this.m_font.equalsIgnoreCase("") || this.m_font.equalsIgnoreCase("TextMask");
  383.       var1 = ((Applet)this).getParameter("fontStyle");
  384.       if (var1 != null) {
  385.          this.m_fontStyle = var1;
  386.       }
  387.  
  388.       var1 = ((Applet)this).getParameter("fontSize");
  389.       if (var1 != null) {
  390.          this.m_fontSize = Integer.parseInt(var1);
  391.       }
  392.  
  393.       ((Component)this).setBackground(this.m_bgColor);
  394.       MediaTracker var2 = new MediaTracker(this);
  395.       if (this.m_textMask) {
  396.          this.m_textImage = ((Applet)this).getImage(((Applet)this).getDocumentBase(), this.m_text);
  397.          var2.addImage(this.m_textImage, 1);
  398.       } else {
  399.          byte var3 = 0;
  400.          if (this.m_fontStyle.equalsIgnoreCase("bold")) {
  401.             var3 = 1;
  402.          }
  403.  
  404.          if (this.m_fontStyle.equalsIgnoreCase("italic")) {
  405.             var3 = 2;
  406.          }
  407.  
  408.          if (this.m_fontStyle.equalsIgnoreCase("bolditalic")) {
  409.             var3 = 3;
  410.          }
  411.  
  412.          Font var4 = new Font(this.m_font, var3, this.m_fontSize);
  413.          ((Component)this).setFont(var4);
  414.          this.m_fm = ((Component)this).getFontMetrics(var4);
  415.          this.m_textWidth = this.m_fm.stringWidth(this.m_text);
  416.       }
  417.  
  418.       int var33 = ((Component)this).size().width;
  419.       int var34 = ((Component)this).size().height;
  420.       if (this.m_normalType == 1) {
  421.          this.m_srcImage = ((Applet)this).getImage(((Applet)this).getDocumentBase(), this.m_image);
  422.          var2.addImage(this.m_srcImage, 2);
  423.       } else {
  424.          this.m_srcImage = ((Component)this).createImage(var33, var34);
  425.          Graphics var5 = this.m_srcImage.getGraphics();
  426.          var5.setColor(this.m_color);
  427.          var5.fillRect(0, 0, var33, var34);
  428.       }
  429.  
  430.       if (this.m_hoverType == 1) {
  431.          this.m_srcHoverImage = ((Applet)this).getImage(((Applet)this).getDocumentBase(), this.m_hoverImage);
  432.          var2.addImage(this.m_srcHoverImage, 3);
  433.       }
  434.  
  435.       try {
  436.          var2.waitForAll();
  437.          this.m_textImageError = var2.isErrorID(1);
  438.          this.m_srcImageError = var2.isErrorID(2);
  439.          this.m_srcHoverImageError = var2.isErrorID(3);
  440.       } catch (InterruptedException var16) {
  441.       }
  442.  
  443.       int var35 = this.m_srcImage.getWidth(this);
  444.       int var6 = this.m_srcImage.getHeight(this);
  445.       int var7 = var35;
  446.       int var8 = var6;
  447.       if (this.m_hoverType == 1) {
  448.          var7 = this.m_srcHoverImage.getWidth(this);
  449.          var8 = this.m_srcHoverImage.getHeight(this);
  450.       }
  451.  
  452.       if (this.m_textMask) {
  453.          this.m_textImageWidth = this.m_textImage.getWidth(this);
  454.          this.m_textImageHeight = this.m_textImage.getHeight(this);
  455.       }
  456.  
  457.       MediaTracker var9 = new MediaTracker(this);
  458.       this.m_applyEffectWait = false;
  459.       if (this.m_textMask && this.m_textColor != Color.black && !this.m_textImageError) {
  460.          this.m_textImage = this.applyEffect(this.m_textImage, 7, this.m_textColor);
  461.          var9.addImage(this.m_textImage, 3);
  462.          this.m_applyEffectWait = true;
  463.       }
  464.  
  465.       if (this.m_hoverType == 2) {
  466.          this.m_srcHoverImage = this.applyEffect(this.m_srcImage, this.m_effect, this.m_hoverColor);
  467.          var9.addImage(this.m_srcHoverImage, 2);
  468.          this.m_applyEffectWait = true;
  469.       }
  470.  
  471.       if (this.m_applyEffectWait) {
  472.          try {
  473.             var9.waitForAll();
  474.          } catch (InterruptedException var15) {
  475.          }
  476.       }
  477.  
  478.       try {
  479.          this.m_docUrl = new URL(((Applet)this).getDocumentBase(), this.m_url);
  480.       } catch (MalformedURLException var14) {
  481.       }
  482.  
  483.       if (!this.m_sound.equalsIgnoreCase("")) {
  484.          this.m_audio = ((Applet)this).getAudioClip(((Applet)this).getDocumentBase(), this.m_sound);
  485.       }
  486.  
  487.       if (!this.m_hoverSound.equalsIgnoreCase("")) {
  488.          this.m_hoverAudio = ((Applet)this).getAudioClip(((Applet)this).getDocumentBase(), this.m_hoverSound);
  489.       }
  490.  
  491.       if (var35 == var7 && var6 == var8 && var35 > 0 && var6 > 0) {
  492.          this.m_noErase = true;
  493.          Image var10 = ((Component)this).createImage(var35, var6);
  494.          Graphics var11 = var10.getGraphics();
  495.          var11.setColor(this.m_bgColor);
  496.          var11.fillRect(0, 0, var35, var6);
  497.          var11.drawImage(this.m_srcImage, 0, 0, (ImageObserver)null);
  498.          this.m_srcImage = var10;
  499.          Image var12 = ((Component)this).createImage(var35, var6);
  500.          Graphics var13 = var12.getGraphics();
  501.          var13.setColor(this.m_bgColor);
  502.          var13.fillRect(0, 0, var35, var6);
  503.          var13.drawImage(this.m_srcHoverImage, 0, 0, (ImageObserver)null);
  504.          this.m_srcHoverImage = var12;
  505.       }
  506.  
  507.    }
  508.  
  509.    public boolean mouseDrag(Event var1, int var2, int var3) {
  510.       return true;
  511.    }
  512.  
  513.    public Image applyEffect(Image var1, int var2, Color var3) {
  514.       int var6 = ((Component)this).size().width;
  515.       int var7 = ((Component)this).size().height;
  516.       fphoverx var5 = new fphoverx(var6, var7, var3, var2);
  517.       FilteredImageSource var8 = new FilteredImageSource(var1.getSource(), var5);
  518.       Image var4 = ((Component)this).createImage(var8);
  519.       return var4;
  520.    }
  521. }
  522.